/**
 * Copyright © 2016-2025 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.terracloud.server.common.data.device;

import com.terracloud.server.common.data.BaseData;
import com.terracloud.server.common.data.id.DeviceAccessControlRuleId;
import com.terracloud.server.common.data.id.TenantId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Schema
@Data
@EqualsAndHashCode(callSuper = true)
public class DeviceAccessControlRule extends BaseData<DeviceAccessControlRuleId> {

    @Schema(description = "租户ID", requiredMode = Schema.RequiredMode.REQUIRED)
    private TenantId tenantId;

    @Schema(description = "规则类型：设备ID或IP地址", requiredMode = Schema.RequiredMode.REQUIRED)
    private DeviceAccessControlRuleType type;

    @Schema(description = "规则值：设备ID或IP地址", requiredMode = Schema.RequiredMode.REQUIRED)
    private String value;

    @Schema(description = "规则是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
    private boolean enabled;
    
    @Schema(description = "访问控制模式：BLACKLIST/WHITELIST", requiredMode = Schema.RequiredMode.REQUIRED)
    private DeviceAccessControlMode mode;
    
    @Schema(description = "规则描述信息")
    private String description;

    public DeviceAccessControlRule() {
        super();
        this.enabled = true;
    }

    public DeviceAccessControlRule(DeviceAccessControlRuleId id) {
        super(id);
    }

    public DeviceAccessControlRule(DeviceAccessControlRule rule) {
        super(rule);
        this.tenantId = rule.getTenantId();
        this.type = rule.getType();
        this.value = rule.getValue();
        this.enabled = rule.isEnabled();
        this.mode = rule.getMode();
        this.description = rule.getDescription();
    }

    @Override
    public String toString() {
        return "DeviceAccessControlRule{" +
                "tenantId=" + tenantId +
                ", type=" + type +
                ", value='" + value + '\'' +
                ", enabled=" + enabled +
                ", mode=" + mode +
                ", description='" + description + '\'' +
                '}';
    }
}